package com.cy.ajax.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class AjaxController {
    private List<String> list=new ArrayList<>();//假设这是存储名字的数据库

    @PostMapping("/doSave")
    public String doSave(String name){
        list.add(name);
        return "save ok";
    }

    @GetMapping("/doCheck")
    public String doCheck(String name){
        return list.contains(name)?name+"已存在":"";
    }

    @CrossOrigin//让这个url支持跨域访问
    @GetMapping("/doAjaxGet")
    public String doAjaxGet() throws InterruptedException {
        System.out.println("===doAjaxGet===");
        Thread.sleep(10000);
        return "Ajax Get Request Result";
    }
}
